package net.apps123.mqtt;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;

import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.IMqttToken;


public class ConnectCallBackHandler implements IMqttActionListener {

    private Context context;

    public ConnectCallBackHandler(Context context) {
        this.context=context;
    }

    public ConnectCallBackHandler() {

    }

    @Override
    public void onSuccess(IMqttToken iMqttToken) {
        Log.d("ConnectCallBackHandler","连接成功");
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                if(context!=null){
                    Toast.makeText(context,"连接成功",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    @Override
    public void onFailure(IMqttToken iMqttToken, Throwable throwable) {
        Log.d("ConnectCallBackHandler","连接失败");
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                if(context!=null){
                    Toast.makeText(context,"连接失败",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
